﻿// Decompiled with JetBrains decompiler
// Type: UnityEngine.Snapping
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E6AE6B5A-2752-4B07-9528-C8B77C62CE79
// Assembly location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
// XML documentation location: C:\Users\windys\Unity\2021.3.39f1c1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.xml

#nullable disable
namespace UnityEngine
{
  /// <summary>
  ///   <para>Snap values to rounded increments.</para>
  /// </summary>
  public static class Snapping
  {
    internal static bool IsCardinalDirection(Vector3 direction)
    {
      return (double) Mathf.Abs(direction.x) > 0.0 && Mathf.Approximately(direction.y, 0.0f) && Mathf.Approximately(direction.z, 0.0f) || (double) Mathf.Abs(direction.y) > 0.0 && Mathf.Approximately(direction.x, 0.0f) && Mathf.Approximately(direction.z, 0.0f) || (double) Mathf.Abs(direction.z) > 0.0 && Mathf.Approximately(direction.x, 0.0f) && Mathf.Approximately(direction.y, 0.0f);
    }

    /// <summary>
    ///   <para>Rounds value to the closest multiple of snap.</para>
    /// </summary>
    /// <param name="val">The value to round.</param>
    /// <param name="snap">The increment to round to.</param>
    /// <returns>
    ///   <para>The rounded value.</para>
    /// </returns>
    public static float Snap(float val, float snap)
    {
      return (double) snap == 0.0 ? val : snap * Mathf.Round(val / snap);
    }

    /// <summary>
    ///   <para>Rounds value to the closest multiple of snap.</para>
    /// </summary>
    /// <param name="val">The value to round.</param>
    /// <param name="snap">The increment to round to.</param>
    /// <returns>
    ///   <para>The rounded value.</para>
    /// </returns>
    public static Vector2 Snap(Vector2 val, Vector2 snap)
    {
      return (Vector2) new Vector3((double) Mathf.Abs(snap.x) < (double) Mathf.Epsilon ? val.x : snap.x * Mathf.Round(val.x / snap.x), (double) Mathf.Abs(snap.y) < (double) Mathf.Epsilon ? val.y : snap.y * Mathf.Round(val.y / snap.y));
    }

    /// <summary>
    ///   <para>Rounds value to the closest multiple of snap.</para>
    /// </summary>
    /// <param name="val">The value to round.</param>
    /// <param name="snap">The increment to round to.</param>
    /// <param name="axis">Restrict snapping to the components on these axes.</param>
    /// <returns>
    ///   <para>The rounded value.</para>
    /// </returns>
    public static Vector3 Snap(Vector3 val, Vector3 snap, SnapAxis axis = SnapAxis.All)
    {
      return new Vector3((axis & SnapAxis.X) == SnapAxis.X ? Snapping.Snap(val.x, snap.x) : val.x, (axis & SnapAxis.Y) == SnapAxis.Y ? Snapping.Snap(val.y, snap.y) : val.y, (axis & SnapAxis.Z) == SnapAxis.Z ? Snapping.Snap(val.z, snap.z) : val.z);
    }
  }
}
